package net.zjitc.servlet;

import net.zjitc.domain.Book;
import net.zjitc.service.BookService;
import net.zjitc.service.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by Administrator on 2017/10/9.
 */
@WebServlet(name = "ListBookServlet",urlPatterns = "/listBookServlet")
public class ListBookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BookService bookService=new BookServiceImpl();
        List<Book> list=bookService.findAll();
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();
        out.write("图书列表如下:<br/>");
        for(Book b:list){
            out.write(b.getId()+":"+b.getName()+"<a href=\"/Web/purchaseServlet?id="+b.getId()+"\">点击购买</a><br/>");
        }
    }
}
